<?php
include_once("funtion/tpl.php");
    
$form_Content = trim($postObj->Content);

$prower=$mysql->getLine("SELECT * FROM address_book where weixin_UserName='$fromUsername';");

if((!$prower)||($mc->get($fromUsername . "_do") == "Prower"))//找不到用户记录
{   
    if(($form_MsgType == "text")&&($mc->get($fromUsername . "_do") == "Prower"))
    {  
       $prower=$mysql->getLine("SELECT * FROM address_book where student_name ='$form_Content';");
      if($prower)
      {
       if($prower['weixin_UserName']!=NULL)
       { 
          $contentStr = "注册失败 用户名已被注册 请从新输入昵称"; 
         
          $resultStr = sprintf($imageTpl, $fromUsername, $toUsername,$contentStr , "","","");
          echo $resultStr;
          exit;          
       }
       else 
       {
            $mysql->runSql("UPDATE address_book SET weixin_UserName='$fromUsername' WHERE student_name ='$form_Content';");
            $mc->delete($fromUsername . "_do", 0);
             include_once("function/Menu.php");
             exit;    //注册成功    
       }
      }
          
       else
       {
           $mysql->runSql("INSERT INTO address_book (weixin_UserName,student_name) VALUES ('$fromUsername','$form_Content');");
           $mc->delete($fromUsername . "_do", 0);
           $contentStr = "成功注册。你的名字为\n".$form_Content; 
           $description="\n回复【菜单】进入主页获取所有功能！！！！";
           $contentStr.= $description;
           $resultStr = sprintf($imageTpl, $fromUsername, $toUsername,$contentStr , "","","");
           echo $resultStr;
           exit;     
       }
    }
    else
    {
    $contentStr = "为了保障你的权益 请在对话框输入你的昵称注册";
    $description="本班学生务必输入真实姓名，否则部分功能失效。游客访问可输入昵称。";
    $resultStr = sprintf($imageTpl, $fromUsername, $toUsername,$contentStr , "","","");
    $mc->set($fromUsername . "_do", "Prower",0,600);
    echo $resultStr;
    exit;
     }
    
}
else 
{
  $connect=$mysql->getLine("SELECT * FROM address_book where weixin_UserName='$fromUsername';");
}


?>